package CustomExceptions;

import java.util.Scanner;

public class Login {
    public static void main(String[] args) {

        while (true) {
            try {
                login();
                break;
            }catch (NameNoConformException e) {
                System.out.println("报异常：NameNoConformException");
                System.out.println("请重新输入:");

            }catch (PasswordNoConformException e) {
                System.out.println("报异常：PasswordNoConformException");
                System.out.println("请重新输入:");
            }
        }
    }

    public static void login() throws NameNoConformException, PasswordNoConformException {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名:");
        String name = scanner.nextLine();
        System.out.print("请输入密码:");
        String password = scanner.nextLine();


        String defaultName = "admit";
        String defaultPassword = "123456";
        if ( !defaultName.equals(name)) {
            throw new NameNoConformException("账号名字不正确！！！");

        }
        if ( !(defaultPassword.equals(password))) {
            throw new PasswordNoConformException("密码不正确！！！");
        }
        System.out.println("登录成功！！！");
    }
}
